package com.lianxi.dto;






import java.util.ArrayList;

/**
 *
 * @author wh
 * @date 2018/1/14
 */
public class ResultUtil {


    public static AjaxDto success(Object object){
        AjaxDto ajaxDto = new AjaxDto();
        ajaxDto.setResult(200);
        ajaxDto.setMsg("成功");
        ajaxDto.setObj(object);
        return  ajaxDto;
    }

    public static AjaxDto success(String msg, Object object){
        AjaxDto ajaxDto = new AjaxDto();
        ajaxDto.setResult(200);
        ajaxDto.setMsg(msg);
        ajaxDto.setObj(object);
        return ajaxDto;
    }

    public static AjaxDto success(){
        return success(new ArrayList<>());
    }

    public static AjaxDto fail(Integer code, String msg){
        AjaxDto ajaxDto = new AjaxDto();
        ajaxDto.setMsg(msg);
        ajaxDto.setResult(code);
        ajaxDto.setObj("");
        return ajaxDto;
    }

    public static AjaxDto fail(Integer code, String msg, Object obj){
        AjaxDto ajaxDto = new AjaxDto();
        ajaxDto.setResult(code);
        ajaxDto.setMsg(msg);
        ajaxDto.setObj(obj);
        return ajaxDto;
    }

    public static AjaxDto fail(String message){
        AjaxDto fail = new AjaxDto();
        fail.setMsg(message);
        fail.setResult(0);
        return  fail;
    }

    public static <T> AjaxDto fail(String message, T data){
        AjaxDto fail = fail(message);
        fail.setObj(data);
        return  fail;
    }

    public static AjaxDto fail(String message, int code){
        AjaxDto fail = fail(message);
        fail.setResult(code);
        return  fail;
    }
}
